﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Security.Cryptography;
using System.Text;

namespace SMSSnew.CLASSES
{
    public class encrypt_decryptCLZ
    {

        string cipherData;
        byte[] cipherbytes;
        byte[] plainbytes;
        byte[] plainbytes2;
        byte[] plainkey;

        SymmetricAlgorithm desObj = Rijndael.Create();

        public void encryption()
        {
            cipherData = "text to encrypt";
            plainbytes = Encoding.ASCII.GetBytes(cipherData);
            plainkey = Encoding.ASCII.GetBytes("0123456789abcdef");
            desObj.Key = plainkey;
            desObj.Mode = CipherMode.CBC;
            desObj.Padding = PaddingMode.PKCS7;
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            CryptoStream cs = new CryptoStream(ms, desObj.CreateEncryptor(), CryptoStreamMode.Write);
            cs.Write(plainbytes, 0, plainbytes.Length);
            cs.Close();
            cipherbytes = ms.ToArray();
            ms.Close();
            string encryptedText = Encoding.ASCII.GetString(cipherbytes);
        }

        public void decryption()
        {
            System.IO.MemoryStream ms1 = new System.IO.MemoryStream(cipherbytes);
            CryptoStream cs1 = new CryptoStream(ms1, desObj.CreateDecryptor(), CryptoStreamMode.Read);

            cs1.Read(cipherbytes, 0, cipherbytes.Length);
            plainbytes2 = ms1.ToArray();
            cs1.Close();
            ms1.Close();

            string decryptedText = Encoding.ASCII.GetString(plainbytes2);

        }
    }
}
